package com.maven.front.controller.manageCourse;


import com.maven.front.bean.Result;
import com.maven.front.bean.SysSubject;
import com.maven.front.service.manageSubject.SysSubjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//         对专业类进行操作

@Slf4j
@CrossOrigin //解决跨域问题
@RestController
@RequestMapping("admin/sysSubject")
public class SysSubjectController {

    @Autowired
    private SysSubjectService sysSubjectService;

    @GetMapping("selectSysSubject")
    public Result selectSysSubject(){
         return sysSubjectService.selectSysSubject();
    }

    //    获取所有专业父节点
    @GetMapping("getSubject")
    public Result getSubject(){
        List<SysSubject> list = sysSubjectService.select();
        if (CollectionUtils.isEmpty(list)){
            return new Result(10005, "查询成功！", null);
        } else {
            return new Result(200, "查询成功！", list);
        }
    }

//    根据父节点ID获取所有子节点数据
    @GetMapping("selectParentId")
    public Result getParentId(Integer subjectId){
        return sysSubjectService.getParentId(subjectId);
    }


    //    根据前台传递过来的专业ID，获取当前专业数据,返回给前台，便于修改
    @GetMapping("selectByPrimaryKey")
    public Result selectByPrimaryKey(Integer subjectId){
        return sysSubjectService.selectByPrimaryKey(subjectId);
    }

    //    删除专业
    @PostMapping("deleteZtreeId")
    public Result deleteZtreeId(String pid){
        log.info("专业ID："+pid);
        return  sysSubjectService.deleteSubjectId(pid);
    }

    //    修改专业信息
    @PostMapping("updateSubject")
    public Result updateZtree(SysSubject sysSubject){
        return sysSubjectService.updateSubject(sysSubject);
    }

    @PostMapping("addSubject")
    public Result addSubject(Integer parentId, String subjectName){
        return sysSubjectService.addSubject(parentId, subjectName);
    }


}